package thread;

public class Demo10 {

    private static boolean isRunning = true;

    public static void main(String[] args) throws InterruptedException {
        //boolean isRunning = true;
        Thread t = new Thread(() -> {
            while (isRunning) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t线程 已经结束");
        });

        t.start();

        Thread.sleep(3000);

        //3s之后，主线程修改isRunning的值，从而通过t结束
        System.out.println("控制t 线程结束");
        isRunning = false;
    }
}
